
#pragma once

class IPALDebuggingServices;
class IPALMemoryServices;
class XFixedSizeAllocator;
struct IPALCriticalSection;
class IPALThreadingServices;

extern IPALDebuggingServices * GetPALDebuggingServices();
extern IPALMemoryServices * GetPALMemoryServices();
extern IPALThreadingServices * GetPALThreadingServices();
extern XFixedSizeAllocator *s_pControlBlockAllocator;


#if defined(_DEBUG)
#define XASSERT(e) do \
{\
	if (!(e)) \
	{\
		if ( GetPALDebuggingServices()->XcpTrace(\
		1u,\
		__FILEW__,\
		__LINE__,\
		0,\
		_STR2WSTR(#e),\
		NULL) )\
		{\
			if ( IsDebuggerPresent() )\
			{\
				DebugBreak();\
			}\
		}\
		\
	}\
} while (0)

#else // !DEBUG
#define XASSERT(e) ((void)0)
#endif




#if defined(_DEBUG)
#define XASSERT_WITH_HR(e,hrin) \
	if (!(e)) \
	{\
		hr = hrin;\
		if(GetPALDebuggingServices()->GetTraceFlags() & 2)\
		{\
			if ( GetPALDebuggingServices()->XcpTrace(\
			8u,\
			__FILEW__,\
			__LINE__,\
			0,\
			_STR2WSTR(#e),\
			NULL) )\
			{\
				if ( IsDebuggerPresent() )\
				{\
					DebugBreak();\
				}\
			}\
		}\
	return hr;\
	}
#else // !DEBUG
#define XASSERT_WITH_HR(e,hrin) ((void)0)
#endif


#if defined(_DEBUG)
#define TRACE_ENSURE1(e,msg) do \
{\
	if (!(e)) \
	{\
		if ( GetPALDebuggingServices()->XcpTrace(\
		1u,\
		__FILEW__,\
		__LINE__,\
		0,\
		_STR2WSTR(#e),\
		msg) )\
		{\
			if ( IsDebuggerPresent() )\
			{\
				DebugBreak();\
			}\
		}\
	}\
} while (0)

#else // !DEBUG
#define TRACE_ENSURE1(e,msg) ((void)0)
#endif


#if defined(_DEBUG)
#define TRACE_ENSURE2(e,msg,msg1) do \
{\
	if (!(e)) \
	{\
		if ( GetPALDebuggingServices()->XcpTrace(\
		1u,\
		__FILEW__,\
		__LINE__,\
		0,\
		_STR2WSTR(#e),\
		msg,\
		msg1) )\
		{\
			if ( IsDebuggerPresent() )\
			{\
				DebugBreak();\
			}\
		}\
	}\
} while (0)

#else // !DEBUG
#define TRACE_ENSURE2(e,msg,msg1) ((void)0)
#endif


//hr = 0x8007000Eu;
//if ( GetPALDebuggingServices()->GetTraceFlags() & 2 )
//{
//	GetPALDebuggingServices()->XcpTrace(
//		5u,
//		L"windows\\dxaml\\xcp\\pal\\inc\\XFixedSizeAllocator.h",
//		73,
//		hr,
//		L"m_pBlock = new XUINT8[static_cast<XUINT32>(cBufferSize)]",
//		0);
//}

#if defined(_DEBUG)
#define XASSERT_NOTNULL_WITH_HR(e,hrin) \
	if (!(e)) \
	{\
		hr = hrin;\
		if(GetPALDebuggingServices()->GetTraceFlags() & 2)\
		{\
			if ( GetPALDebuggingServices()->XcpTrace(\
			1u,\
			__FILEW__,\
			__LINE__,\
			0,\
			_STR2WSTR(#e),\
			NULL) )\
			{\
				if ( IsDebuggerPresent() )\
				{\
					DebugBreak();\
				}\
			}\
		}\
		return hr;\
	}
#else // !DEBUG
#define XASSERT_NOTNULL_WITH_HR(e,hrin) ((void)0)
#endif



#if defined(_DEBUG)
#define XASSERT_SUCCESSED(e) \
{\
	hr = e;\
	if(FAILED(hr))\
	{\
		if ( GetPALDebuggingServices()->GetTraceFlags() & 2 )\
		{\
			GetPALDebuggingServices()->XcpTrace(\
				4u,\
				__FILEW__,\
				__LINE__,\
				hr,\
				_STR2WSTR(#e),\
				NULL);\
		}\
		return hr;\
	}\
}

#else // !DEBUG
#define XASSERT_SUCCESSED(e) ((void)0)
#endif


#if defined(_DEBUG)
#define XASSERT_FAILED_GOTO(e,gotolabel) \
{\
	hr = e;\
	if(FAILED(hr))\
	{\
		if ( GetPALDebuggingServices()->GetTraceFlags() & 2 )\
		{\
			GetPALDebuggingServices()->XcpTrace(\
			4u,\
			__FILEW__,\
			__LINE__,\
			hr,\
			_STR2WSTR(#e),\
			NULL);\
		}\
		goto gotolabel;\
	}\
}

#else // !DEBUG
#define XASSERT_FAILED_GOTO(e,gotolabel) ((void)0)
#endif


#if defined(_DEBUG)
#define XASSERT_NOTNULL_FAILED_GOTO(e,gotolabel) \
{\
	if (!(e)) \
	{\
		if(GetPALDebuggingServices()->GetTraceFlags() & 2)\
		{\
			if ( GetPALDebuggingServices()->XcpTrace(\
				1u,\
				__FILEW__,\
				__LINE__,\
				0,\
				_STR2WSTR(#e),\
				NULL) )\
			{\
				if ( IsDebuggerPresent() )\
				{\
					DebugBreak();\
				}\
			}\
		}\
		goto gotolabel;\
	}\
}
#else // !DEBUG
#define XASSERT_NOTNULL_FAILED_GOTO(e,hrin) ((void)0)
#endif